package Drawers;

import org.eclipse.swt.graphics.*;

public class GCDrawer implements Drawer 
{
	private GC _gc;
	private PaletteData _palette;
	private boolean _stoped;
	private int _width;
	
	public GCDrawer(GC gc, PaletteData pallete)
	{
		_stoped = false;
		_gc = gc;
		_palette = pallete;
	}
	
	public void Stop()
	{
		_stoped = true;
	}
	
	public boolean ToStop()
	{
		return _stoped;
	}
	
	public void Start(Point size, PaletteData palette)
	{
		_width = size.x;
		_palette = palette;
	}
	
	public void Finish(){}
	
	public void PutPixel(int x, int y, int color)
	{
		_gc.setForeground(new Color(_gc.getDevice(), _palette.getRGB(color)));
		_gc.drawPoint(x, y);
	}
	
	public void PutPixel(int iter, byte r, byte g, byte b)
	{
		_gc.setForeground(new Color(_gc.getDevice(), r, g , b));
		int y = (int)Math.floor((double)iter / (double)_width);
		_gc.drawPoint(iter - y * _width  , y);
	}
	
	public int BytesPerLine()
	{
		return _width * 3;
	}
}
